package ao.util.data;

/**
 * User: alex
 * Date: 10-May-2010
 * Time: 10:29:15 PM
 */
public class Tuples
{
    //-------------------------------------------------------------------------



    //-------------------------------------------------------------------------
    private Tuples() {}


    //-------------------------------------------------------------------------
    public static <A, B> Pair<A, B> create(A first, B second)
    {
        return new Pair<A, B>(first, second);
    }

    public static <A, B, C> Triple<A, B, C> create(
            A first, B second, C third)
    {
        return new Triple<A, B, C>(first, second, third);
    }



    //-------------------------------------------------------------------------
    public static class Pair<A, B> {
        private final A a;
        private final B b;

        public Pair(A first, B second) {
            a = first;
            b = second;
        }

        public A first () {  return a;  }
        public B second() {  return b;  }

        @Override public String toString() {
            StringBuilder str = new StringBuilder();
            str.append('(');
            toInnerString(str);
            str.append(')');
            return str.toString();
        }

        protected void toInnerString(StringBuilder str) {
            str.append(a).append(", ").append(b);
        }

    }

    public static class Triple<A, B, C> extends Pair<A, B> {
        private final C c;

        public Triple(A first, B second, C third) {
            super(first, second);
            c = third;
        }

        public C third() {  return c;  }

        protected void toInnerString(StringBuilder str) {
            super.toInnerString( str );
            str.append(", ").append( c );
        }
    }
}
